﻿using System;
using System.Windows;
using System.Windows.Controls;
using Silverlight.Windows;
using Silverlight.Windows.Controls;

namespace Sample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = new RoutedCommand((x,target) => {
                if (Application.Current.IsRunningOutOfBrowser && 
                    Application.Current.HasElevatedPermissions)
                {
                    var modalWindow = new Window { Title = "Modal Window", Width = 256, Height = 160 };
                    modalWindow.Content = new TextBlock { Text = x.ToString(), FontSize = 96 };
                    var ownerWindow = Window.GetWindow(target);
                    modalWindow.ShowDialog(ownerWindow, StartupLocation.CenterOwner, false);
                }
            });
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var began = Environment.TickCount;
            if (Application.Current.IsRunningOutOfBrowser &&
                Application.Current.HasElevatedPermissions)
            {
                var win = new Window { Title = "Secondary Window", Width = 256, Height = 128 };
                win.Content = new SecondaryWindow();
                win.Show();
            }
            else
            {
                MessageBox.Show("You must first install the application");
            }
            var completed = Environment.TickCount;
            System.Diagnostics.Debug.WriteLine(completed - began);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var child = new ChildWindow { Title = "Child Window" };
            child.Content = new TextBlock { Text = "Content" };
            child.Show();
            
        }
    }
}
